/*//////////////////////////////////////////////////////////////////////////////
//
//                  INTEL CORPORATION PROPRIETARY INFORMATION
//     This software is supplied under the terms of a license agreement or
//     nondisclosure agreement with Intel Corporation and may not be copied
//     or disclosed except in accordance with the terms of that agreement.
//          Copyright(c) 2005-2007 Intel Corporation. All Rights Reserved.
//
*/

#include "umc_defs.h"
#if defined (UMC_ENABLE_MP3_INT_AUDIO_ENCODER)

#ifndef __MP3ENC_OWN_INT_H__
#define __MP3ENC_OWN_INT_H__

#include "mp3enc_own.h"

#ifdef __cplusplus
extern "C" {
#endif

#define MUL32_MP3_32S(x, y) \
  (Ipp32s)(((Ipp64s)((Ipp64s)(x) * (Ipp64s)(y)))>>32)
#define _IPPS_MUL32_MP3_32S MUL32_MP3_32S

typedef Ipp32s samplefbout[2][18][32];

struct _MP3Enc {
    MP3Enc_com com;

    Ipp32s ca_int[8], cs_int[8];

//  ------//-------
    VM_ALIGN16_DECL(Ipp16s) input_buffer_short[4][1152 + 224 + 576];
    VM_ALIGN16_DECL(samplefbout) fbout_data[3];
    VM_ALIGN16_DECL(Ipp32s) mdct_out_int[2][2][576];
    samplefbout *fbout_int[3];
    Ipp32s fbout_prev;

    Ipp16s ipa_sprdngf_long[MAX_PPT_LONG * MAX_PPT_LONG];
    Ipp16s ipa_sprdngf_short[MAX_PPT_SHORT * MAX_PPT_SHORT];

    Ipp32s ipa_nb_long[4][2][MAX_PPT_LONG];

    Ipp32s pa_ratio_l[2][4][SBBND_L];
    Ipp32s pa_ratio_s[2][4][3][SBBND_S];
    Ipp32s pa_ratio_l_next[4][SBBND_L];
    Ipp32s pa_ratio_s_next[4][3][SBBND_S];

    Ipp32s ms_pwr[2];
    Ipp32s ms_ncoef[2], ms_dcoef[2], ms_ncoef_next, ms_dcoef_next;

    IppsFFTSpec_R_16s* ipa_pFFTSpecShort;
    IppsFFTSpec_R_16s* ipa_pFFTSpecLong;
    Ipp8u* ipa_pBuffer;

    Ipp32s mdct_rqnt[576];
    Ipp32s mdct_line_abs_int[576];
    Ipp16s mdct_line_abs_short[576];
    Ipp16s mdct_scaled_short[576];

    VM_ALIGN16_DECL(Ipp16s) ipa_r[4][3][512];
    VM_ALIGN16_DECL(Ipp16s) ipa_re[4][3][512];
    VM_ALIGN16_DECL(Ipp16s) ipa_im[4][3][512];

    VM_ALIGN16_DECL(Ipp16s) ipa_r_short[4][3][3][128];
    VM_ALIGN16_DECL(Ipp16s) ipa_re_short[4][3][3][128];
    VM_ALIGN16_DECL(Ipp16s) ipa_im_short[4][3][3][128];

    Ipp32s ipa_current_f_r_index[4];  // Can be 0, 1, 2

    Ipp32s ipa_next_frame_PE[4];
    Ipp32s ipa_curr_frame_PE[4];
    Ipp32s ipa_curr_frame_PE_st[2][4];

    Ipp32s m_even[2];
    Ipp32s m_line[2][2];

    Ipp32s start_common_scalefac;
    Ipp32s finish_common_scalefac;
    Ipp32s common_scalefactor_update[2];
    Ipp32s last_frame_common_scalefactor[2];
    Ipp32s pa_iblen_long; // = 512
    Ipp32s pa_iblen_short;// = 128

    Ipp32s ipa_rScaleFactor[4][3];
    Ipp32s ipa_nb_longScaleFactor[4];

    Ipp32s ipa_longScale;
    Ipp32s ipa_shortScale;

    Ipp32s pa_num_ptt_long;
    Ipp32s pa_num_ptt_short;

    Ipp32s ipa_nb_curr_index[4];
    Ipp32s ipa_nb_prev_index[4];

    Ipp32s ipa_desired_block_type[4];
    Ipp32s ipa_next_desired_block_type[2][4];
};

void   mp3ienc_mdctInit(MP3Enc *state);
Ipp32s mp3ienc_mdctInSubband(MP3Enc *state, Ipp32s *in, Ipp32s *out, Ipp32s block_type);
Ipp32s mp3ienc_mdctBlock(MP3Enc *state);

void   mp3ienc_quantCalcAvailableBits(MP3Enc *state);
Ipp32s mp3ienc_quantization(MP3Enc *state);
void   mp3ienc_quantMainLoop(MP3Enc *state, Ipp32s gr, Ipp32s ch,
                             Ipp16s* mdct_scaled_short,
                             Ipp32s pow34_scaleFact);

Ipp32s mp3ienc_psychoacousticInit(MP3Enc *state, Ipp8u *mem, Ipp32s *size);
void   mp3ienc_psychoacoustic(MP3Enc *state, Ipp16s **input_data);
void   mp3ienc_psychoacousticLongWindow(MP3Enc *state,
                                        Ipp16s *input_data,
                                        Ipp32s* rsqr_long,
                                        Ipp32s* rsqr_longScale,
                                        Ipp32s ch);
void   mp3ienc_psychoacousticShortWindow(MP3Enc *state,
                                         Ipp16s *input_data,
                                         Ipp32s* s_en,
                                         Ipp32s ch);

#ifdef __cplusplus
}
#endif

#endif

#endif //UMC_ENABLE_MP3_INT_AUDIO_ENCODER
